<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <style>
        .aui-bar-nav {
            background-color: #FFF;
            color: #000;
        }

        .aui-bar-nav .aui-iconfont {
            color: #000!important;
            font-weight: bold;
        }
    </style>
</head>

<body>
    <header id="header" class="aui-bar aui-bar-nav">
        <a class="aui-pull-left aui-btn" tapmode onclick="comeBack()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">绑定支付宝</div>
    </header>
    <div class="aui-content money_ti bind_account">
        <div class="bottom-box">
            <ul class="aui-list aui-form-list">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">真实姓名</div>
                        <div class="aui-list-item-input">
                            <input id="cname" type="text" placeholder="请输入真实姓名">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">支付宝账号</div>
                        <div class="aui-list-item-input">
                            <input id="account" type="text" placeholder="请输入支付宝账号">
                        </div>
                    </div>
                </li>
            </ul>

        </div>
        <div class="bottom-btn"><button type="button" tapmode onclick="corfirm(this)">绑定</button></div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../script/md5.min.js"></script>
<script type="text/javascript">
    var userInfo;
    apiready = function() {
        initHeard();
        userInfo = $api.getStorage('user');
        userInfo = JSON.parse(userInfo)
        if (userInfo.apply_name) {
            $("#cname").val(userInfo.apply_name);
        }
        if (userInfo.apply_account) {
            $("#account").val(userInfo.apply_account);
        }
    };

    function corfirm(that) {
        var cname = $("#cname").val();
        var alipay = $("#account").val();
        if (cname == '') {
            _msg("请输入真实姓名");
            return false;
        }
        if (alipay == '') {
            _msg("请输入支付宝账号");
            return false;
        }
        var data = {
            apply_name: cname,
            apply_account: alipay
        };
        _ajax("user/bindAlipay", data, function(res, err) {
            if (res) {
                _msg(res.msg);
                if (res.errCode == 1) {
                    userInfo.apply_name = cname;
                    userInfo.apply_account = alipay;
                    $api.setStorage('user', JSON.stringify(userInfo));
                    setTimeout(function() {
                        comeBack();
                    }, 800)
                } else if (res.errCode == -1) {
                    // alert("绑定账号失败")
                    openWin('login');
                }
            } else {
                _msg("网络错误");
            }
        })
    };
</script>

</html>
